﻿using System;
using System.Collections.Generic;

namespace Poly2Tri
{
	// Token: 0x020003E7 RID: 999
	public class DelaunayTriangle
	{
		// Token: 0x06001B18 RID: 6936 RVA: 0x000AC26B File Offset: 0x000AA46B
		public DelaunayTriangle(TriangulationPoint p1, TriangulationPoint p2, TriangulationPoint p3)
		{
			this.Points[0] = p1;
			this.Points[1] = p2;
			this.Points[2] = p3;
		}

		// Token: 0x170003C0 RID: 960
		// (get) Token: 0x06001B19 RID: 6937 RVA: 0x000AC29A File Offset: 0x000AA49A
		public FixedBitArray3 EdgeIsConstrained
		{
			get
			{
				return this.mEdgeIsConstrained;
			}
		}

		// Token: 0x170003C1 RID: 961
		// (get) Token: 0x06001B1A RID: 6938 RVA: 0x000AC2A2 File Offset: 0x000AA4A2
		// (set) Token: 0x06001B1B RID: 6939 RVA: 0x000AC2AA File Offset: 0x000AA4AA
		public bool IsInterior { get; set; }

		// Token: 0x06001B1C RID: 6940 RVA: 0x000AC2B4 File Offset: 0x000AA4B4
		public int IndexOf(TriangulationPoint p)
		{
			int num = this.Points.IndexOf(p);
			if (num == -1)
			{
				throw new Exception("Calling index with a point that doesn't exist in triangle");
			}
			return num;
		}

		// Token: 0x06001B1D RID: 6941 RVA: 0x000AC2E1 File Offset: 0x000AA4E1
		public int IndexCWFrom(TriangulationPoint p)
		{
			return (this.IndexOf(p) + 2) % 3;
		}

		// Token: 0x06001B1E RID: 6942 RVA: 0x000AC2EE File Offset: 0x000AA4EE
		public int IndexCCWFrom(TriangulationPoint p)
		{
			return (this.IndexOf(p) + 1) % 3;
		}

		// Token: 0x06001B1F RID: 6943 RVA: 0x000AC2FB File Offset: 0x000AA4FB
		public bool Contains(TriangulationPoint p)
		{
			return this.Points.Contains(p);
		}

		// Token: 0x06001B20 RID: 6944 RVA: 0x000AC30C File Offset: 0x000AA50C
		private void MarkNeighbor(TriangulationPoint p1, TriangulationPoint p2, DelaunayTriangle t)
		{
			int num = this.EdgeIndex(p1, p2);
			if (num == -1)
			{
				throw new Exception("Error marking neighbors -- t doesn't contain edge p1-p2!");
			}
			this.Neighbors[num] = t;
		}

		// Token: 0x06001B21 RID: 6945 RVA: 0x000AC344 File Offset: 0x000AA544
		public void MarkNeighbor(DelaunayTriangle t)
		{
			bool flag = t.Contains(this.Points[0]);
			bool flag2 = t.Contains(this.Points[1]);
			bool flag3 = t.Contains(this.Points[2]);
			if (flag2 && flag3)
			{
				this.Neighbors[0] = t;
				t.MarkNeighbor(this.Points[1], this.Points[2], this);
			}
			else if (flag && flag3)
			{
				this.Neighbors[1] = t;
				t.MarkNeighbor(this.Points[0], this.Points[2], this);
			}
			else
			{
				if (!flag || !flag2)
				{
					throw new Exception("Failed to mark neighbor, doesn't share an edge!");
				}
				this.Neighbors[2] = t;
				t.MarkNeighbor(this.Points[0], this.Points[1], this);
			}
		}

		// Token: 0x06001B22 RID: 6946 RVA: 0x000AC44C File Offset: 0x000AA64C
		public void ClearNeighbors()
		{
			int index = 0;
			DelaunayTriangle delaunayTriangle = null;
			this.Neighbors[2] = delaunayTriangle;
			delaunayTriangle = delaunayTriangle;
			this.Neighbors[1] = delaunayTriangle;
			this.Neighbors[index] = delaunayTriangle;
		}

		// Token: 0x06001B23 RID: 6947 RVA: 0x000AC484 File Offset: 0x000AA684
		public void ClearNeighbor(DelaunayTriangle triangle)
		{
			if (this.Neighbors[0] == triangle)
			{
				this.Neighbors[0] = null;
			}
			else if (this.Neighbors[1] == triangle)
			{
				this.Neighbors[1] = null;
			}
			else if (this.Neighbors[2] == triangle)
			{
				this.Neighbors[2] = null;
			}
		}

		// Token: 0x06001B24 RID: 6948 RVA: 0x000AC4F8 File Offset: 0x000AA6F8
		public void Clear()
		{
			for (int i = 0; i < 3; i++)
			{
				DelaunayTriangle delaunayTriangle = this.Neighbors[i];
				if (delaunayTriangle != null)
				{
					delaunayTriangle.ClearNeighbor(this);
				}
			}
			this.ClearNeighbors();
			int index = 0;
			TriangulationPoint triangulationPoint = null;
			this.Points[2] = triangulationPoint;
			triangulationPoint = triangulationPoint;
			this.Points[1] = triangulationPoint;
			this.Points[index] = triangulationPoint;
		}

		// Token: 0x06001B25 RID: 6949 RVA: 0x000AC562 File Offset: 0x000AA762
		public TriangulationPoint OppositePoint(DelaunayTriangle t, TriangulationPoint p)
		{
			return this.PointCWFrom(t.PointCWFrom(p));
		}

		// Token: 0x06001B26 RID: 6950 RVA: 0x000AC571 File Offset: 0x000AA771
		public DelaunayTriangle NeighborCWFrom(TriangulationPoint point)
		{
			return this.Neighbors[(this.Points.IndexOf(point) + 1) % 3];
		}

		// Token: 0x06001B27 RID: 6951 RVA: 0x000AC58E File Offset: 0x000AA78E
		public DelaunayTriangle NeighborCCWFrom(TriangulationPoint point)
		{
			return this.Neighbors[(this.Points.IndexOf(point) + 2) % 3];
		}

		// Token: 0x06001B28 RID: 6952 RVA: 0x000AC5AB File Offset: 0x000AA7AB
		public DelaunayTriangle NeighborAcrossFrom(TriangulationPoint point)
		{
			return this.Neighbors[this.Points.IndexOf(point)];
		}

		// Token: 0x06001B29 RID: 6953 RVA: 0x000AC5C4 File Offset: 0x000AA7C4
		public TriangulationPoint PointCCWFrom(TriangulationPoint point)
		{
			return this.Points[(this.IndexOf(point) + 1) % 3];
		}

		// Token: 0x06001B2A RID: 6954 RVA: 0x000AC5DC File Offset: 0x000AA7DC
		public TriangulationPoint PointCWFrom(TriangulationPoint point)
		{
			return this.Points[(this.IndexOf(point) + 2) % 3];
		}

		// Token: 0x06001B2B RID: 6955 RVA: 0x000AC5F4 File Offset: 0x000AA7F4
		private void RotateCW()
		{
			TriangulationPoint value = this.Points[2];
			this.Points[2] = this.Points[1];
			this.Points[1] = this.Points[0];
			this.Points[0] = value;
		}

		// Token: 0x06001B2C RID: 6956 RVA: 0x000AC64B File Offset: 0x000AA84B
		public void Legalize(TriangulationPoint oPoint, TriangulationPoint nPoint)
		{
			this.RotateCW();
			this.Points[this.IndexCCWFrom(oPoint)] = nPoint;
		}

		// Token: 0x06001B2D RID: 6957 RVA: 0x000AC668 File Offset: 0x000AA868
		public override string ToString()
		{
			return string.Concat(new object[]
			{
				this.Points[0],
				",",
				this.Points[1],
				",",
				this.Points[2]
			});
		}

		// Token: 0x06001B2E RID: 6958 RVA: 0x000AC6C0 File Offset: 0x000AA8C0
		public void MarkNeighborEdges()
		{
			for (int i = 0; i < 3; i++)
			{
				if (this.EdgeIsConstrained[i] && this.Neighbors[i] != null)
				{
					this.Neighbors[i].MarkConstrainedEdge(this.Points[(i + 1) % 3], this.Points[(i + 2) % 3]);
				}
			}
		}

		// Token: 0x06001B2F RID: 6959 RVA: 0x000AC738 File Offset: 0x000AA938
		public void MarkEdge(DelaunayTriangle triangle)
		{
			for (int i = 0; i < 3; i++)
			{
				if (this.EdgeIsConstrained[i])
				{
					triangle.MarkConstrainedEdge(this.Points[(i + 1) % 3], this.Points[(i + 2) % 3]);
				}
			}
		}

		// Token: 0x06001B30 RID: 6960 RVA: 0x000AC794 File Offset: 0x000AA994
		public void MarkEdge(List<DelaunayTriangle> tList)
		{
			foreach (DelaunayTriangle delaunayTriangle in tList)
			{
				for (int i = 0; i < 3; i++)
				{
					if (delaunayTriangle.EdgeIsConstrained[i])
					{
						this.MarkConstrainedEdge(delaunayTriangle.Points[(i + 1) % 3], delaunayTriangle.Points[(i + 2) % 3]);
					}
				}
			}
		}

		// Token: 0x06001B31 RID: 6961 RVA: 0x000AC830 File Offset: 0x000AAA30
		public void MarkConstrainedEdge(int index)
		{
			this.mEdgeIsConstrained[index] = true;
		}

		// Token: 0x06001B32 RID: 6962 RVA: 0x000AC83F File Offset: 0x000AAA3F
		public void MarkConstrainedEdge(DTSweepConstraint edge)
		{
			this.MarkConstrainedEdge(edge.P, edge.Q);
		}

		// Token: 0x06001B33 RID: 6963 RVA: 0x000AC854 File Offset: 0x000AAA54
		public void MarkConstrainedEdge(TriangulationPoint p, TriangulationPoint q)
		{
			int num = this.EdgeIndex(p, q);
			if (num != -1)
			{
				this.mEdgeIsConstrained[num] = true;
			}
		}

		// Token: 0x06001B34 RID: 6964 RVA: 0x000AC880 File Offset: 0x000AAA80
		public double Area()
		{
			double num = this.Points[0].X - this.Points[1].X;
			double num2 = this.Points[2].Y - this.Points[1].Y;
			return Math.Abs(num * num2 * 0.5);
		}

		// Token: 0x06001B35 RID: 6965 RVA: 0x000AC8E8 File Offset: 0x000AAAE8
		public TriangulationPoint Centroid()
		{
			double x = (this.Points[0].X + this.Points[1].X + this.Points[2].X) / 3.0;
			double y = (this.Points[0].Y + this.Points[1].Y + this.Points[2].Y) / 3.0;
			return new TriangulationPoint(x, y);
		}

		// Token: 0x06001B36 RID: 6966 RVA: 0x000AC97C File Offset: 0x000AAB7C
		public int EdgeIndex(TriangulationPoint p1, TriangulationPoint p2)
		{
			int num = this.Points.IndexOf(p1);
			int num2 = this.Points.IndexOf(p2);
			bool flag = num == 0 || num2 == 0;
			bool flag2 = num == 1 || num2 == 1;
			bool flag3 = num == 2 || num2 == 2;
			if (flag2 && flag3)
			{
				return 0;
			}
			if (flag && flag3)
			{
				return 1;
			}
			if (flag && flag2)
			{
				return 2;
			}
			return -1;
		}

		// Token: 0x06001B37 RID: 6967 RVA: 0x000ACA00 File Offset: 0x000AAC00
		public bool GetConstrainedEdgeCCW(TriangulationPoint p)
		{
			return this.EdgeIsConstrained[(this.IndexOf(p) + 2) % 3];
		}

		// Token: 0x06001B38 RID: 6968 RVA: 0x000ACA28 File Offset: 0x000AAC28
		public bool GetConstrainedEdgeCW(TriangulationPoint p)
		{
			return this.EdgeIsConstrained[(this.IndexOf(p) + 1) % 3];
		}

		// Token: 0x06001B39 RID: 6969 RVA: 0x000ACA50 File Offset: 0x000AAC50
		public bool GetConstrainedEdgeAcross(TriangulationPoint p)
		{
			return this.EdgeIsConstrained[this.IndexOf(p)];
		}

		// Token: 0x06001B3A RID: 6970 RVA: 0x000ACA72 File Offset: 0x000AAC72
		protected void SetConstrainedEdge(int idx, bool ce)
		{
			this.mEdgeIsConstrained[idx] = ce;
		}

		// Token: 0x06001B3B RID: 6971 RVA: 0x000ACA84 File Offset: 0x000AAC84
		public void SetConstrainedEdgeCCW(TriangulationPoint p, bool ce)
		{
			int idx = (this.IndexOf(p) + 2) % 3;
			this.SetConstrainedEdge(idx, ce);
		}

		// Token: 0x06001B3C RID: 6972 RVA: 0x000ACAA8 File Offset: 0x000AACA8
		public void SetConstrainedEdgeCW(TriangulationPoint p, bool ce)
		{
			int idx = (this.IndexOf(p) + 1) % 3;
			this.SetConstrainedEdge(idx, ce);
		}

		// Token: 0x06001B3D RID: 6973 RVA: 0x000ACACC File Offset: 0x000AACCC
		public void SetConstrainedEdgeAcross(TriangulationPoint p, bool ce)
		{
			int idx = this.IndexOf(p);
			this.SetConstrainedEdge(idx, ce);
		}

		// Token: 0x06001B3E RID: 6974 RVA: 0x000ACAE9 File Offset: 0x000AACE9
		public bool GetDelaunayEdgeCCW(TriangulationPoint p)
		{
			return this.EdgeIsDelaunay[(this.IndexOf(p) + 2) % 3];
		}

		// Token: 0x06001B3F RID: 6975 RVA: 0x000ACB01 File Offset: 0x000AAD01
		public bool GetDelaunayEdgeCW(TriangulationPoint p)
		{
			return this.EdgeIsDelaunay[(this.IndexOf(p) + 1) % 3];
		}

		// Token: 0x06001B40 RID: 6976 RVA: 0x000ACB19 File Offset: 0x000AAD19
		public bool GetDelaunayEdgeAcross(TriangulationPoint p)
		{
			return this.EdgeIsDelaunay[this.IndexOf(p)];
		}

		// Token: 0x06001B41 RID: 6977 RVA: 0x000ACB2D File Offset: 0x000AAD2D
		public void SetDelaunayEdgeCCW(TriangulationPoint p, bool ce)
		{
			this.EdgeIsDelaunay[(this.IndexOf(p) + 2) % 3] = ce;
		}

		// Token: 0x06001B42 RID: 6978 RVA: 0x000ACB46 File Offset: 0x000AAD46
		public void SetDelaunayEdgeCW(TriangulationPoint p, bool ce)
		{
			this.EdgeIsDelaunay[(this.IndexOf(p) + 1) % 3] = ce;
		}

		// Token: 0x06001B43 RID: 6979 RVA: 0x000ACB5F File Offset: 0x000AAD5F
		public void SetDelaunayEdgeAcross(TriangulationPoint p, bool ce)
		{
			this.EdgeIsDelaunay[this.IndexOf(p)] = ce;
		}

		// Token: 0x06001B44 RID: 6980 RVA: 0x000ACB74 File Offset: 0x000AAD74
		public bool GetEdge(int idx, out DTSweepConstraint edge)
		{
			edge = null;
			if (idx < 0 || idx > 2)
			{
				return false;
			}
			TriangulationPoint triangulationPoint = this.Points[(idx + 1) % 3];
			TriangulationPoint triangulationPoint2 = this.Points[(idx + 2) % 3];
			return triangulationPoint.GetEdge(triangulationPoint2, out edge) || triangulationPoint2.GetEdge(triangulationPoint, out edge);
		}

		// Token: 0x06001B45 RID: 6981 RVA: 0x000ACBD8 File Offset: 0x000AADD8
		public bool GetEdgeCCW(TriangulationPoint p, out DTSweepConstraint edge)
		{
			int num = this.IndexOf(p);
			int idx = (num + 2) % 3;
			return this.GetEdge(idx, out edge);
		}

		// Token: 0x06001B46 RID: 6982 RVA: 0x000ACBFC File Offset: 0x000AADFC
		public bool GetEdgeCW(TriangulationPoint p, out DTSweepConstraint edge)
		{
			int num = this.IndexOf(p);
			int idx = (num + 1) % 3;
			return this.GetEdge(idx, out edge);
		}

		// Token: 0x06001B47 RID: 6983 RVA: 0x000ACC20 File Offset: 0x000AAE20
		public bool GetEdgeAcross(TriangulationPoint p, out DTSweepConstraint edge)
		{
			int num = this.IndexOf(p);
			int idx = num;
			return this.GetEdge(idx, out edge);
		}

		// Token: 0x04001D3B RID: 7483
		public FixedArray3<TriangulationPoint> Points;

		// Token: 0x04001D3C RID: 7484
		public FixedArray3<DelaunayTriangle> Neighbors;

		// Token: 0x04001D3D RID: 7485
		private FixedBitArray3 mEdgeIsConstrained;

		// Token: 0x04001D3E RID: 7486
		public FixedBitArray3 EdgeIsDelaunay;
	}
}
